package com.cogent.dynamicform.form.impl;

import java.util.HashMap;

import com.cogent.business.helper.EnumHelper;
import com.cogent.common.util.MapUtil;
import com.cogent.common.util.StringUtil;
import com.cogent.dynamicform.domain.BaseFormColumnDomain;
import com.cogent.dynamicform.domain.FormColumnDomain;
import com.cogent.dynamicform.form.AbstractDynamicForm;

public class RadioDynamicFormImpl extends AbstractDynamicForm {
	public String genQueryField(BaseFormColumnDomain formColumnDomain, HashMap formMap) {
		return "";
	}
	
	public String genInputField(FormColumnDomain formColumnDomain, HashMap formMap) {
		if(formColumnDomain.getViewmodel() > 0)
			return getShowValue(formColumnDomain, formMap) + "&nbsp;";
		StringBuffer str = new StringBuffer();
		String className = "input_middle";
		if(!StringUtil.isEmpty(formColumnDomain.getShowclass()))
			className = formColumnDomain.getShowclass();
		str.append(EnumHelper.getEnumRadio(formColumnDomain.getName(), formColumnDomain.getTypecode()
				, className, MapUtil.getStringValue(formMap, formColumnDomain.getName())));
		if(formColumnDomain.isIsrequired())
			str.append("<span class=\"txt_red\">&nbsp;*</span>");
		
		return str.toString();
	}
	
	public String getShowValue(BaseFormColumnDomain formColumnDomain, HashMap formMap) {
		if(formColumnDomain.getShowtype() == 1)
			return "&nbsp;";
		String name = formColumnDomain.getName();
		if(name.indexOf(".") > 0)
			name = name.substring(name.indexOf(".") + 1);
		String ret = EnumHelper.getEnumValue(formColumnDomain.getTypecode(), MapUtil.getStringValue(formMap, name));
		if(StringUtil.isEmpty(ret))
			ret = "&nbsp;";
		return ret;
	}
}